package implementation1.gui;

import javax.swing.*;
import java.util.ResourceBundle;

/**
 * Created: 21.11.11
 *
 * @author Jenda Kolena, jendakolena@gmail.com
 * @version 1.0
 */
public class Message
{
    static ResourceBundle bundle = ResourceBundle.getBundle("implementation1.res.messages");

    /**
     * Show message.
     *
     * @param window      Parent window.
     * @param message     Message text.
     * @param messageType Message type.
     */
    private static void showMessage(ShellWindow window, String message, int messageType)
    {
        String title = window == null ? "m2j-os" : "Shell - " + window.getLoginName();
        JOptionPane.showMessageDialog(window, message, title, messageType);
    }

    /**
     * Show info message.
     *
     * @param window  Parent window.
     * @param message Message text.
     */
    public static void show(ShellWindow window, String message)
    {
        showMessage(window, message, JOptionPane.INFORMATION_MESSAGE);
    }

    /**
     * Show info message.
     *
     * @param message Message text.
     */
    public static void show(String message)
    {
        Message.show(null, message);
    }

    /**
     * Show error message.
     *
     * @param window  Parent window.
     * @param message Message text.
     */
    public static void showError(ShellWindow window, String message)
    {
        showMessage(window, message, JOptionPane.ERROR_MESSAGE);
    }

    /**
     * Show error message.
     *
     * @param message Message text.
     */
    public static void showError(String message)
    {
        Message.showError(null, message);
    }

    public static void showException(Exception e)
    {
        Message.showError(null, String.format(bundle.getString("error.ExceptionThrown"), e.getMessage()));
    }
}
